package com.jqsoft.launcher.util;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017-12-06.
 */

public class Util {

    public static int getIntFromString(String s){
        int i = 0;
        try {
            i = Integer.parseInt(s);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            i = 0;
        }
        return i;
    }

    public static float getFloatFromString(String s){
        float f = 0f;
        try {
            f=Float.parseFloat(s);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            f=0f;
        }
        return f;
    }

    public static String getFileNameFromDateTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss_SSS");
        Date date = new Date();
        String name = sdf.format(date);
        return name;
    }

    public static String checkString(String s){
        if (s == null){
            return "";
        } else {
            return s;
        }
    }

    public static String trimString(String s){
        s = checkString(s);
        return s.trim();
    }
}
